Skip to content

Global resource defaults implementation#3151

Merged
dunglas merged 5 commits into
api-platform:masterfrom
bpolaszek:fix-3099-2
Oct 14, 2019
Merged

Global resource defaults implementation#3151
dunglas merged 5 commits into
api-platform:masterfrom
bpolaszek:fix-3099-2

Conversation

@bpolaszek

Copy link
Copy Markdown
Contributor
Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #3099
License MIT

This PR introduces a defaults configuration as a new implementation of #3099 (#3135 was dropped).

This one doesn't rely on a low-priority DefaultsResourceMetadataFactory as suggested first (because low priority means late access to some normalization logic) and implements the defaults pattern in AnnotationResourceMetadataFactory and ExtractorResourceMetadataFactory, making configuration more consistent, which means support for short-hand config like this:

api_platform:
    defaults:
        itemOperations: ["get"]
        collectionOperations: ["get"]
        mercure: true

Default configuration is now flattened at the bundle configuration level, removing the attributes sublevel to improve DX and normalizing all keys to snake_case to follow Symfony standards (both camelCase and snake_case are actually supported to be less error-prone, attributes being mostly documented as annotations):

api_platform:
    defaults:
        description:          ~
        iri:                  ~
        item_operations:      ~
        collection_operations: ~
        graphql:              ~
        security:             ~
        security_message:     ~
        security_post_denormalize: ~
        security_post_denormalize_message: ~
        cache_headers:        ~
        denormalization_context: ~
        deprecation_reason:   ~
        elasticsearch:        ~
        fetch_partial:        ~
        force_eager:          ~
        formats:              ~
        filters:              ~
        hydra_context:        ~
        mercure:              ~
        messenger:            ~
        normalization_context: ~
        order:                ~
        pagination_client_enabled: ~
        pagination_client_items_per_page: ~
        pagination_client_partial: ~
        pagination_enabled:   ~
        pagination_fetch_join_collection: ~
        pagination_items_per_page: ~
        maximum_items_per_page: ~
        pagination_maximum_items_per_page: ~
        pagination_partial:   ~
        pagination_via_cursor: ~
        route_prefix:         ~
        swagger_context:      ~
        validation_groups:    ~
        sunset:               ~
        input:                ~
        output:               ~
        openapi_context:      ~

Comment thread src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php Outdated
Comment thread src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php Outdated
Comment thread src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php Outdated
Comment thread src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php Outdated
Comment thread src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php Outdated
Comment thread src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php Outdated
Comment thread src/Metadata/Resource/Factory/AnnotationResourceMetadataFactory.php Outdated

@soyuka soyuka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't we add a DefaultMetadataFactory that is called prior to extractor/annotation that sets defaults based on the injected defaults?
#3135 (comment)

I'm not fond of the transformations done in the Extension.

Comment thread src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php Outdated
Comment thread src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php Outdated
Comment thread src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php Outdated
@dunglas
dunglas merged commit 74ee7ef into api-platform:master Oct 14, 2019
@dunglas

dunglas commented Oct 14, 2019

Copy link
Copy Markdown
Member

Thanks @bpolaszek!

warslett pushed a commit to BiffBangPow/core that referenced this pull request Oct 18, 2019
* Add defaults configuration

* Suggest defaults in configuration

* Apply changes from code review

* Add deprecation notices for legacy defaults

* Apply @dunglas' suggestions
norkunas pushed a commit to norkunas/core that referenced this pull request Dec 2, 2019
* Add defaults configuration

* Suggest defaults in configuration

* Apply changes from code review

* Add deprecation notices for legacy defaults

* Apply @dunglas' suggestions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants